package com.hns.can.energy.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.energy.vo.NewEnergy;
import com.hns.can.energy.vo.SpeedAnalysisVo;
import com.hns.can.master.entity.CommEnerConsStatInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 转苏分析service
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class SpeedAnalysisService extends CommonService {
	
	@Autowired
	private FillCodeDscValue fillCodeDscValue;

	/**
	 * 查询转速分析
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@LeftOrgAnnotation()
    @Transactional
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public Pagination searchSpeedAnalysis(NewEnergy vo)throws Exception {
        Pagination page = this.myBatisPage("speedAnalysis.searchSpeedAnalysisCount", "speedAnalysis.searchSpeedAnalysis", vo, SpeedAnalysisVo.class);
        List list = page.getData();
        fillColVal(list);
        page.setData(list);
        return page;
    }
	
	/**
	 * 查询导出数据
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@LeftOrgAnnotation()
    @Transactional
    @SuppressWarnings({ "unchecked" })
    public  List<SpeedAnalysisVo> exportSpeedAnalysis(NewEnergy vo)throws Exception {
        List<SpeedAnalysisVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("speedAnalysis.searchSpeedAnalysis", vo), SpeedAnalysisVo.class);
        fillColVal(list);
        return list;
    }
	
	/**
	 * 查询线路图表
	 * @param vo
	 * @return
	 * @throws Exception
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@Transactional
    @SuppressWarnings({ "unchecked" })
    public  List<CommEnerConsStatInfoEntity> searchLineEnergyChart(NewEnergy vo)throws Exception {
        List<CommEnerConsStatInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("speedAnalysis.searchLineEnergyChart", vo), SpeedAnalysisVo.class);
        fillColVal(list);
        return list;
    }
	
	
	/**
     * 填充字段值
     * @param list
     * @throws Exception
     * @author:zhangy
     * @email:zhangyu2222z@sina.cn
     */
    @SuppressWarnings("rawtypes")
	private void fillColVal(List list) throws Exception {
		//转化生成线路名称
        Map<String,String> map = new HashMap<String,String>();
        map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo1 = new FillParamsVo("lineId", map);
        //转化生成机构名称
        map = new HashMap<String,String>();
        map.put("organName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo2 = new FillParamsVo("organId", map);
        //转化生成车牌号、车辆类别、车辆、燃料类型
        map= new HashMap<String,String>();
        map.put("licPltNo",  GlobalConst.DEFAULT_CACHE_VALUE);
        map.put("engiNo", "engiNo");
        //转化生成驾驶员名称
        FillParamsVo fileVo3 = new FillParamsVo("carId", map);
        map = new HashMap<String,String>();
        map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);
        FillParamsVo fileVo4 = new FillParamsVo("drvId", map);
        fillCodeDscValue.fillInfoValue(list,new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO, 
            GlobalConst.CACHE_KEY_BASE_DRV_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN, 
            GlobalConst.CACHE_KEY_BASE_CAR_INFO}, fileVo1, fileVo2, fileVo3, fileVo4);
	}
	
}
